package com.woniuxy.ssm.powermag.controller;

import com.github.pagehelper.Page;
import com.woniuxy.ssm.entity.ResEntity;
import com.woniuxy.ssm.entity.RoleEntity;
import com.woniuxy.ssm.powermag.service.IRoleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RequestMapping("/role")
@RestController
public class RoleController {
    @Resource
    private IRoleService roleServiceImpl;

    @PostMapping("/{id}")
    public ResEntity save(RoleEntity roleEntity){
        roleServiceImpl.save(roleEntity);
        return ResEntity.builder().code(200).msg("新增成功").build();
    }

    @PutMapping("/{id}")
    public ResEntity update(RoleEntity roleEntity){
        roleServiceImpl.update(roleEntity);
        return ResEntity.builder().code(200).msg("修改成功").build();
    }

    @DeleteMapping("/{id}")
    public ResEntity delete(@PathVariable("id") Long id){
        roleServiceImpl.deleteById(id);
        return ResEntity.builder().code(200).msg("删除成功").build();
    }

    @GetMapping("/{id}")
    public ResEntity get(@PathVariable("id") Long id){
        RoleEntity role = roleServiceImpl.getById(id);
        return ResEntity.builder().code(200).msg("查询成功")
                .datas(role).build();
    }

    @GetMapping("/page")
    public ResEntity page(Integer page,Integer rows,RoleEntity roleEntity){
        Page<RoleEntity> datas = roleServiceImpl.page(page, rows, roleEntity);

        return ResEntity.builder().code(200).msg("查询成功")
                .datas(datas).build();
    }

}
